package ru.tulupov.guessgame;

/**
 * Main class
 * @author <a href="mailto:zhekka3@gmail.com">Eugene Tulupov</a>
 */
public class Main {

	public static void main(String[] args) {
		Parser parser = new Parser(System.in);
		Game game = new Game();

		System.out.println("Guess game");
		System.out.println(String.format(
				"Try to guess a number from %d to %d. You have %d attempts.",
				Game.MIN_VALUE, Game.MAX_VALUE, Game.MAX_ATTEMPT_COUNT));

		while (true) {
			try {
				int number = parser.parse();
				Game.Result result = game.guess(number);

				if (result == Game.Result.LESS) {
					System.out.println("Your number is less than mine.");
				} else if (result == Game.Result.EQUAL) {
					System.out.println("You win!");
					break;
				} else if (result == Game.Result.MORE) {
					System.out.println("Your number is more than mine.");
				}

			} catch (ParseException e) {
				System.err.println("Wrong input!");
			} catch (EOFParseException e) {
				System.exit(0);
			} catch (GameOverException e) {
				System.out.println("Game over!");
				System.exit(0);
			}
		}

	}

}
